################################################################################
# Description: Install zsh,
#              Please input "Y",when it ask `Do you want to change your default shell to zsh? [Y/n] y`
# Parameter  : `install`
# Author     : houxuecheng
# Date       : 20220217
# Version    : 1.0
# Modifiy    :
################################################################################

set -e

main() {
    apt remove zsh -y
    apt install zsh -y
    chsh -s /bin/zsh

    if [ -d "/root/.oh-my-zsh" ]; then
        rm -rf "/root/.oh-my-zsh"
        echo "remove the existed folder of oh-my-zsh"
    fi

    if [ -f "./install.sh" ]; then
        rm -rf "./install.sh"
    fi

    wget https://raw.staticdn.net/ohmyzsh/ohmyzsh/master/tools/install.sh
    if [ $? -ne 0 ]; then
        echo "wget file failed"
        exit 0
    fi

    sed -i '53s/github.com/gitclone.com\/github.com/' install.sh
    if [ $? -ne 0 ]; then
        echo "substitute github.com failed"
        exit 0
    fi

    sed -i '503d' install.sh
    if [ $? -ne 0 ]; then
        echo "remove 'zsh -l' failed"
        exit 0
    fi
    sh ./install.sh

    git clone -q https://gitclone.com/github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
    git clone -q https://gitclone.com/github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    sed -i '11s/ZSH_THEME=\"robbyrussell\"/ZSH_THEME=\"dallas\"/' /root/.zshrc
    sed -i '73s/git/git zsh-autosuggestions zsh-syntax-highlighting/' /root/.zshrc

    rm -rf "install.sh"

    echo "Successfully install ZSH!!!"

    zsh -l
    source /root/.zshrc
}

case "$1" in
install)
    main
    ;;
*)
    echo "Usage:$0 install.Please see description!"
    ;;
esac
